<?php use_helper('jQuery')?>

<div id="main_header" class="ui-widget-header ui-corner-all">
    <h3>Datos del Formulario: "<?php echo $element->getTitle() ?>""</h3>
</div>
<div id="main_content" class="ui-widget ui-widget-content ui-corner-all">
    <table>
        <?php if($sf_user->hasCredential('Editar elemento') &&
                ($element->getSection()->getType()->getType() == 'Register' ?
                $sf_user->hasCredential('Editar formulario de registro') : true )
            ):?>
            <tfoot>
                <tr>
                    <td colspan="2">
                         <?php echo jq_link_to_remote(
                                '<span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span>
                                <span class="ui-button-text">Editar</span>',
                            array(
                                'update' => 'main',
                                'url' => url_for('element_edit',$element),
                                'before' => 'clearView();showLoaderMain();',
                                'complete' => 'hideLoader();',
                                'script' => true
                            ), array(
                                'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary',
                                'title' => 'Editar'
                            ))
                        ?>
                    </td>
                </tr>
            </tfoot>
        <?php endif; ?>
        <tbody>
            <tr>
                <th>Sección:</th>
                <td>
                    <?php echo jq_link_to_remote(
                            $element->getSection(),
                        array(
                            'update' => 'main',
                            'url' => url_for('section_show',$element->getSection()),
                            'before' => 'clearView();showLoaderMain();',
                            'complete' => 'hideLoader();',
                            'script' => true
                        )) ?>
                </td>
            </tr>
            <tr>
                <th>Posición:</th>
                <td><?php echo $element->getPosition()?></td>
            </tr>
            <tr>
                <th colspan="2">Numero de Campos: <?php echo $element->getForm()->getFields()->count()?></th>
            </tr>
            <tr>
                <td colspan="2">
                    <table>
                        <?php foreach ($element->getForm()->getFields() as $i=>$field):?>
                            <tr class="<?php echo ($i%2 ? 'odd' : 'even')?>">
                                <th>Etiqueta:</th>
                                <td><?php echo $field->getTitle()?></td>
                            </tr>
                            <tr class="<?php echo ($i%2 ? 'odd' : 'even')?>">
                                <th>Tipo:</th>
                                <td><?php echo $field->getFieldType()?></td>
                            </tr>
                            <?php if($field->getFieldType()->getType() == 'Select'):?>
                                <tr class="<?php echo ($i%2 ? 'odd' : 'even')?>">
                                    <th>Opciones:</th>
                                    <td>
                                        <?php $op = strtok($field->getOptions(), ','); $j=0; ?>
                                        <?php while ($op != false): ?>
                                            <?php echo $op ?>
                                            <?php $j++ ?>
                                            <?php $op = strtok(',')?>
                                            <?php if(($j%3)!=0 && $op!=false):?>
                                                <?php echo (" - ") ?>
                                            <?php else :?>
                                                <?php echo "<br>"?>
                                            <?php endif;?>
                                        <?php endwhile;?>
                                    </td>
                                </tr>
                            <?php endif;?>
                            <tr class="<?php echo ($i%2 ? 'odd' : 'even')?>">
                                <th>Clave:</th>
                                <td>
                                    <?php if ($field->getIsKey() == true): ?>
                                        <img alt="Sí" src="/images/util/check.png">
                                    <?php else: ?>
                                        <img alt="No" src="/images/util/cross.png">
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <tr class="<?php echo ($i%2 ? 'odd' : 'even')?>">
                                <th>Único:</th>
                                <td>
                                    <?php if ($field->getIsUnique() == true): ?>
                                        <img alt="Sí" src="/images/util/check.png">
                                    <?php else: ?>
                                        <img alt="No" src="/images/util/cross.png">
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <tr class="<?php echo ($i%2 ? 'odd' : 'even')?>">
                                <th>Requerido:</th>
                                <td>
                                    <?php if ($field->getIsRequired() == true): ?>
                                        <img alt="Sí" src="/images/util/check.png">
                                    <?php else: ?>
                                        <img alt="No" src="/images/util/cross.png">
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach;?>
                    </table>
                </td>
            </tr>
            <tr>
                <th>Publicado:</th>
                <td>
                    <?php if ($element->getPublished() == true): ?>
                        <img alt="Sí" src="/images/util/check.png">
                    <?php else: ?>
                        <img alt="No" src="/images/util/cross.png">
                    <?php endif; ?>
                </td>
            </tr>
            <tr>
                <th>Fecha de creación:</th>
                <td><?php echo $element->getDateTimeObject('created_at')->format('d/m/Y - g:i a') ?></td>
            </tr>
            <tr>
                <th><label>Ultima modificación:</label></th>
                <td><?php echo $element->getDateTimeObject('updated_at')->format('d/m/Y - g:i a') ?></td>
            </tr>
        </tbody>
    </table>
</div>